import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:nft_shop/res/constant.dart';
import 'package:nft_shop/res/global.dart';

class StatusViews extends StatelessWidget {
  StatusViews(this.status,
      {Key? key, this.onTap, this.color, this.emptyText})
      : super(key: key);
  final int status;
  final GestureTapCallback? onTap;
  final Color? color;
  final String? emptyText;

  @override
  Widget build(BuildContext context) {
    switch (status) {
      case LoadStatusType.networkFailure:
        return new Container(
          width: double.infinity,
          child: new Material(
            color: color ?? Global.kTheme.colorBackground1,
            child: new InkWell(
              onTap: () {
                if (onTap != null) onTap!();
              },
              child: new Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Image.asset("assets/images/error_network.png", width: 100),
                  new Text(
                    "请检查您的网络 \r\n 点击重新加载",
                    textAlign: TextAlign.center,
                    style: TextStyle(fontSize: 14),
                  ),
                ],
              ),
            ),
          ),
        );
        break;
      case LoadStatusType.loading:
        return new Container(
          alignment: Alignment.center,
          child: Center(
            child: new SizedBox(
              width: 24.0,
              height: 24.0,
              child: new CircularProgressIndicator(
                valueColor: AlwaysStoppedAnimation<Color>(Global.kTheme.colorPrimary),
                strokeWidth: 2.0,
              ),
            ),
          ),
        );
        break;
      case LoadStatusType.empty:
        return new Container(
          color: color ?? Global.kTheme.colorBackground1,
          width: double.infinity,
          child: new InkWell(
              onTap: () {
                if (onTap != null) onTap!();
              },
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Image.asset(
                    "assets/images/no.png",
                    width: 100,
                  ),
                  SizedBox(height: 10),
                  new Text(
                    ObjectUtil.isEmpty(emptyText)?"没有数据":emptyText!,
                    textAlign: TextAlign.center,
                    style: TextStyle(
                        fontSize: 14, color: Color(0xFF9CA5B3)),
                  ),
                ],
              )),
        );
        break;
      default:
        return Container();
        break;
    }
  }
}
